package com.hex.ds.hdtp.core.inf.common.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@AllArgsConstructor
public enum FieldType {

    //数字类型筛选
    NUMBER_TYPE("numbertype", Arrays.asList("NUMBER", "BINARY_FLOAT", "BINARY_DOUBLE", "FLOAT", "DECIMAL", "INTEGER", "LONG", "SMALLINT", "BIGINT","INT","DOUBLE","NUMERIC")),
    //字符串类型筛选
    VARCHAR_TYPE("varchartype",Arrays.asList("CHAR", "VARCHAR","VARCHAR2","NVARCHAR","CLOB", "NCHAR", "NVARCHAR2", "NCLOB", "RAW", "BLOB", "BFILE"));


    @Getter
    private final String desc;
    @Getter
    private final List<String> value;

    private static final Map<String, FieldType> FieldTypeToEnumMap = Stream.of(FieldType.values()).collect(Collectors.toMap(e -> e.getDesc(), e ->e));


    public static List<String> fromFieldType(String fieldType) {
        FieldType result = FieldTypeToEnumMap.get(fieldType.toLowerCase());
        if (result == null) {
            // 若字段类型匹配不上 抛出异常
            throw new IllegalArgumentException("Unsupported database name: " + fieldType);
        }
        return result.getValue();
    }


}
